package com.gezi.admin.utils;

import cn.hutool.core.util.NumberUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class CommonUtil {

    public static String jineInt2Str(Object jine){
        return jineInt2Str(jine,false);
    }

    public static String jineInt2Str(Object jine,boolean isH0){
        if(jine == null){
            return "0";
        }
        if(jine instanceof Double){
            return NumberUtil.roundStr(NumberUtil.div((double) jine,100,2),2);
        }
        try {
            int iJine = Integer.parseInt(jine.toString());
            if(isH0){
                return NumberUtil.roundStr(NumberUtil.div(iJine,100,2),2);
            }else{
                return NumberUtil.toStr(NumberUtil.div(iJine,100,2));
            }
        }catch (Exception ex){
            ex.printStackTrace();
            log.info(ex.getMessage());
        }
        return "0";
    }

    public static String jineDouble2Str(Object jine){
        return NumberUtil.roundStr(NumberUtil.div(Double.valueOf(jine.toString()).doubleValue(),100,2),2);
    }

    public static String juli2Str(Object juli){
        return juli2Str(juli,false);
    }

    public static String juli2Str(Object juli,boolean isH0){
        if(juli == null){
            return "0";
        }
        try {
            double iJine = Double.parseDouble(juli.toString());
            if(isH0){
                return NumberUtil.roundStr(NumberUtil.div(iJine,1000,2),2);
            }else{
                return NumberUtil.toStr(NumberUtil.div(iJine,1000,2));
            }
        }catch (Exception ex){
            ex.printStackTrace();
            log.info(ex.getMessage());
        }
        return "0";
    }
}
